package datamining.sequence;

import java.util.ArrayList;
import java.util.Iterator;

public class ItemVector<ItemType> implements Comparable<ItemVector<ItemType>>{

	private int dimensions = 1;
	private ArrayList<ItemType> itemVector;

	public ItemVector(final int dimensions){
		assert dimensions > 0;
		this.dimensions = dimensions;
		itemVector = new ArrayList<ItemType>(this.dimensions);
	}

	public void setItem( int dimension, ItemType item){
		itemVector.set(dimension, item);
	}
	
	public ItemType getItem( int dimension){
		return itemVector.get(dimension);
	}
	
	public ArrayList<ItemType> getItems(){
		return itemVector;
	}

	@Override
	public int compareTo(ItemVector<ItemType> o) {
        Iterator<ItemType> thisIter = itemVector.iterator();
        Iterator<ItemType> anotherIter = o.getItems().iterator();

        while (thisIter.hasNext()) {
                if (!anotherIter.hasNext()) {
                        return 1;
                }

                ItemType i1 = thisIter.next();
                ItemType i2 = anotherIter.next();

                int diff = ((Comparable)i1).compareTo(i2);
                if (diff != 0) {
                        return diff;
                }
        }

        return 0;
	}
}
